<?

// Include Magnet
include('magnet/includes/loader.inc.php');

/*

	// Default example

	// Instance model just setting table name
	$books = new Model('books');

	// Get records!
	// This will return records with default settings (all columns, 10 records by page, etc.)
	$records = $books->browse();
	printer($records);

*/

/*

	// Advanced example

	// Instance model with advanced settings
	$books = new Model(array(
		'table' => 'books',
		'limit' => 5,
		'order' => array(
			'title'
		)
	));

	// Get records!
	// This will return records with the settings you just setted (from table books, 5 items by page, order by title)
	$records = $books->browse();
	printer($records);

*/

/*

	// Instance model and change settings dinamically

	// Instance in classic style
	$books = new Model('books');

	// Edit class options
	$books->options(array(
		'limit' => 10,
		'order' => array(
			'price', 'desc'
		)
	));

	// And get records
	$expensive_books = $books->browse();
	printer($expensive_books);

	// Change settings again
	$books->options(array(
		'limit' => 10,
		'order' => array(
			'rating', 'desc'
		)
	));

	// And get more records
	$best_sellers = $books->browse();
	printer($best_sellers);

*/

/*

	// Instance in classic style
	$books = new Model('books');

	// Get a single item
	$book = $books->details(123);
	printer($book);

*/

/*

	// Set options on the fly
	$books = new Model('books');
	$a = $books->browse(array(
		'limit' => 7,
		'order' => array(
			'title'
		)
	));
	printer($a);

*/


/*

	// Get a browse filtered by IDs
	$books = new Model('books');
	$a = $books->browse(array("id" => array(123, 124)));

*/


/*

	// Get a browse of items with filters
	$books = new Model('books');
	$a = $books->browse(array(
		'limit' => 7,
		'order' => array(
			'title'
		),
		'filters' => array(
			'title' => array(
				'column' => 'title',
				'operator' => 'LIKE',
				'value' => 'man'
			)
		)
	));
	printer($a);

*/

/*

	// Restrict fields or join with another table
	$books = new Model('books');
	$books->options(array(
		'fieldset' => array(
			'browse' => array(
				'title',
				'rating',
				'id_author' => array(
					'index' => 'id_author',
					'join' => 'authors',
					'on' => 'id',
					'get' => 'name',
					'select' => true,
					'alias' => 'author'
				)
			)
		)
	));
	$a = $books->browse();
	printer($a);

*/

/*

	// Restrict fields or join with another table, on the fly
	$books = new Model('books');
	$a = $books->browse(array(
		'fieldset' => array(
			'title',
			'rating',
			'id_author' => array(
				'index' => 'id_author',
				'join' => 'authors',
				'on' => 'id',
				'get' => 'name',
				'select' => true,
				'alias' => 'author'
			)		
		)
	));
	printer($a);

*/

// Wouldn't be better $books->fieldset()...? Maybe it is
// Change "fields" by "columns" in $options


// With all this changes, $options and $params from the controller could be just one



// Autosave list status

$books = new Model('books');

$list = $books->browse(array(
	'limit' => 7,
	'page' => 2,
	'order' => array(
		'title', 'desc'
	),
	'filters' => array(
		'title' => array(
			'column' => 'title',
			'operator' => 'LIKE',
			'value' => 'man'
		),
		'rating' => array(
			'column' => 'rating',
			'operator' => 'LIKE',
			'value' => '4'
		),
		
	)
));





?>
